<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateIbrandStoreTransferTables extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		$prefix = config('ibrand.app.database.prefix', 'ibrand_');
		if (!Schema::hasTable($prefix . 'store_transfer')) {  //库存调拨表
			Schema::create($prefix . 'store_transfer', function (Blueprint $table) {
				$table->increments('id');
				$table->unsignedInteger('out_shop_id')->comment('调出店铺id');
				$table->unsignedInteger('in_shop_id')->comment('调入店铺id');
				$table->string('code', 100)->comment('业务编码');
				$table->unsignedInteger('clerk_id')->comment('调拨人');
				$table->unsignedInteger('total')->default(0)->comment('调拨总数');
				$table->string('remark')->nullable()->comment('备注');
				$table->timestamps();
				$table->softDeletes();
			});
		}

		if (!Schema::hasTable($prefix . 'store_transfer_item')) {  //库存调拨明细表
			Schema::create($prefix . 'store_transfer_item', function (Blueprint $table) {
				$table->increments('id');
				$table->unsignedInteger('transfer_id');
				$table->string('item_type');
				$table->unsignedInteger('item_id');
				$table->unsignedInteger('count')->default(0)->comment('调拨数量');
				$table->unsignedInteger('before_count')->default(0)->comment('调拨前数量');
				$table->text('meta')->nullable(); //detail_id:商品ID；color:颜色;size：尺码；
				$table->unsignedInteger('goods_id');

				$table->timestamps();
				$table->softDeletes();
			});
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		$prefix = config('ibrand.app.database.prefix', 'ibrand_');
		Schema::dropIfExists($prefix . 'store_transfer');
		Schema::dropIfExists($prefix . 'store_transfer_item');
	}
}
